import Cookies from "js-cookie"
const state = {
  showHeader: Cookies.get("showHeader") === "1" ? true : false, //是否展示头部
  showFooter: Cookies.get("showFooter") === "1" ? true : false, //展示底部
  showTagsView: Cookies.get("showTagsView") === "1" ? true : false, //展示tagsView
  theme: Cookies.get("theme") || "normal", //主题
  mode: Cookies.get("mode") || "normal", //模式   正常模式normal  适老模式elder  
  title: "爆米花小布", //系统名称
  logo: require("@/assets/imgs/xiaobu-logo.png") //logo
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    Cookies.set(key, value)
    const booleanList = ["showHeader", "showFooter", "showTagsView"]
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      //如果是布尔列表 转化数据
      if (booleanList.includes(key)) {
        value = value === "1" ? true : false
      }
      state[key] = value
    }
  }
}

const actions = {
  /**
   * @description: 设置参数
   * @param {*} commit
   * @param {*} data
   * @return {*}
   * @author: syx
   */  
  changeSetting({ commit }, data) {
    commit("CHANGE_SETTING", data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
